<extend name='Index/index' />
<block name="main">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">添加管理员</h1>
    </div>
    <br>
<script>
$(function(){
    $('#account').blur(function(){
        var account = $('#account').val();
        $.ajax({
            type:'get',
            url:"<{:U('Admin/check_account')}>",
            data:{'account':account},
            success:function(data){
                if(data == 1){
                    alert('用户名已存在!');
                    $('#account_hidden').val(1);
                    $('#account').val('').focus();
                }else{
                    $('#account_hidden').val(0);
                }
            }
        })
    });
});
</script>
<script>
function admin_add(){
        var account = $('#account').val();
        var password = $('#password').val();
        var group_id = $('#group_id').val();
        var account_hidden = $('#account_hidden').val();
        if(group_id == ''){
            alert('请选择用户组');
            return false;
        }

        if(account == ''){
            alert('请输入账号');
            return false;
        }

        if(password == ''){
            alert('请输入密码');
            return false;
        }

        if(password == ''){
            alert('请输入密码');
            return false;
        }
        
        if(account_hidden == 1){
            alert('账号重复，请重新输入');
            return false;
        }
        var url = "<{:U('Admin/admin_list')}>";
        $.ajax({
            url:"<{:U('Admin/admin_insert')}>",
            type:'post',
            data:{'account':account,'password':password,'group_id':group_id},
            success:function(data){
                alert(data);
                window.location.href = url;
            }
        })
}
</script>

<div class="list">
      <table class="form-group" width="100%" border="0" cellpadding="0" cellspacing="0" class="details">
        <tbody>
          <tr>
            <td><div align="right">用户组：</div></td>
            <td><select class="form-control" name="group_id" id="group_id" style="width:190px">
                    <option value="">----- 请选择用户组 -----</option>
                  <foreach name="data" item="vo">
                    <option value="<{$vo.id}>"><{$vo.title}></option>
                  </foreach>
                </select>
            </td>
          </tr>
          <tr>
            <td width="25%"><div align="right">账号：</div></td>
            <td width="75%"><input class="form-control" type="text" style="width:190px" name="account" id="account" size="24" value="" />
            <input type="hidden" id="account_hidden" value="0" />
            </td>
          </tr>
          <tr>
            <td><div align="right">密码：</div></td>
            <td><input style="width:190px" type="password" class="form-control" name="password" id="password" size="24" value="" /></td>
          </tr>
        </tbody>
  </table>
</div>
     <button type="button" class="btn btn-default" id="button" style="min-width:190px;margin-left:270px" onclick="admin_add();">确 认</button>
</block>
